using System;
using System.Web.UI.Design;

using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Library.WebControls.SimpleButton {
	public class SpButtonDesign : ControlDesigner {
		internal string GetDesignTimeHtml(SpButton sbtn) {
			
			var sw = new StringWriter();
			var tw = new HtmlTextWriter(sw);

			var btn = new HtmlGenericControl("div");
			if (sbtn.ClientEnable)
				btn.Attributes["class"] = sbtn.EnableClass;
			else btn.Attributes["class"] = sbtn.DisableCssClass;

			if (!String.IsNullOrEmpty(sbtn.ImageUrl)) {
				var divImg = new HtmlGenericControl("div");
				divImg.Attributes["class"] = sbtn.ImgCssClass;
				btn.Controls.Add(divImg);
				var img = new Image { ImageUrl = sbtn.ImageUrl };
				divImg.Controls.Add(img);
			}

			var text = new HtmlGenericControl("div");
			btn.Controls.Add(text);
			text.Attributes["class"] = sbtn.TextCssClass;
			text.InnerText = sbtn.Text;
			if (String.IsNullOrEmpty(text.InnerText)) {
				//if (sbtn is SpButtonCallback) {
					//text.InnerText = "SpButtonCallback";
				//} else
					text.InnerText = "SpButton";
			}
			var link = sbtn.CreateCssLink();
			link.RenderControl(tw);
			btn.RenderControl(tw);
			return sw.ToString();
		}
		public override string GetDesignTimeHtml() {
			var sbtn = (SpButton)Component;

			return GetDesignTimeHtml(sbtn);


		}
	}
}
